jQuery(document).bind("keydown",function(e){   
        e=window.event||e;
        if(e.keyCode==116){
        e.keyCode = 0;
        return false; // 屏蔽F5刷新键
        }
     });

jQuery("a[name=operate]").click(function(){
	var title=jQuery(this).attr("attr-title")+"<small>"+jQuery(this).attr("attr-desc")+"</small>";
	jQuery("#pageName").html(title);
	jQuery(".jumbotron").hide();
	jQuery("#loading").removeClass("hide");
	jQuery(".page-head").removeClass("hide");
	jQuery("#pageInfoDiv").show();
	jQuery("#datafiled").hide();
	var url=jQuery(this).attr("attr-url");
	commonAjax(url);
});

function commonAjax(url)
{
	jQuery.post(url,{"ran":getRandom()},function(data){commonAjaxCallBack(data)});
}

function commonAjaxCallBack(data)
{
// alert(data);
	jQuery("#datafiled").html(data);
	jQuery("#pageInfoDiv").hide();
	jQuery("#datafiled").show();
}

function getRandom() {
	return Math.floor(Math.random() * (1000 + 1));
}

jQuery(document).on("click","#btn_jobadd",function (){
	var jobname=jQuery("#jobname").val().trim();
	var displayname=jQuery("#displayname").val().trim();
	var jobid=jQuery("#jobid").val().trim();
	var jobgroup=jQuery("#jobgroup").val().trim();
	var deploymentaddress=jQuery("#deploymentaddress").val().trim();
	var deploymentport=jQuery("#deploymentport").val().trim();
	var backupaddress=jQuery("#backupaddress").val().trim();
	var backupport=jQuery("#backupport").val().trim();
	var linkman=jQuery("#linkman").val().trim();
	if(jobname=="" || displayname=="" || jobid==""||jobgroup==""||deploymentaddress==""||deploymentport==""||linkman=="")
	{
		jQuery("#jobadd_alert").removeClass("hide");
		return false;
	}
	else
	{
		jQuery("#jobadd_alert").addClass("hide");
		jQuery.post("jobAdd.html",
				{
					"ran":getRandom(),
					"jobname":jobname,
					"displayname":displayname,
					"jobid":jobid,
					"jobgroup":jobgroup,
					"deploymentaddress":deploymentaddress,
					"deploymentport":deploymentport,
					"backupaddress":backupaddress,
					"backupport":backupport,
					"linkman":linkman
				},function(data){
			var result=eval('('+data+')');
			if(result.result==true)
			{
				confirm("添加成功");
				commonAjax("jobListPage.html")
			}
			else
			{
				confirm("添加失败，请稍候重试");
				commonAjax("jobAdd.html");
			}
		});
	}
});

jQuery(document).on("click","#btn_jobalarmadd",function (){
	var jobname=jQuery("#jobname").val().trim();
	var displayname=jQuery("#displayname").val().trim();
	var monitorthreshold=jQuery("#monitorthreshold").val().trim();
	var dbmonitordatabase=jQuery("#dbmonitordatabase").val().trim();
	var dbmonitordatabaseuser=jQuery("#dbmonitordatabaseuser").val().trim();
	var dbmonitordatabasepwd=jQuery("#dbmonitordatabasepwd").val().trim();
	var dbmonitortable=jQuery("#dbmonitortable").val().trim();
	var dbmonitorcondition=jQuery("#dbmonitorcondition").val().trim();
	var dbmonitorthreshold=jQuery("#dbmonitorthreshold").val().trim();
	if(jobname=="" || displayname=="" || monitorthreshold=="")
	{
		jQuery("#jobalarmadd_alert").removeClass("hide");
		return false;
	}
	if(dbmonitordatabase!=""||dbmonitordatabaseuser!=""||dbmonitordatabasepwd!=""||dbmonitortable!=""||dbmonitorcondition!=""||dbmonitorthreshold!="")
	{
		if(dbmonitordatabase==""||dbmonitordatabaseuser==""||dbmonitordatabasepwd==""||dbmonitortable==""||dbmonitorcondition==""||dbmonitorthreshold=="")
		{
			jQuery("#jobalarmadd_db_alert").removeClass("hide");
			return false;
		}
		else
		{
			jQuery("#jobalarmadd_alert").addClass("hide");
			jQuery("#jobalarmadd_db_alert").addClass("hide");
			jQuery.post("jobAlarmAdd.html",
					{
						"ran":getRandom(),
						"jobname":jobname,
						"monitorthreshold":monitorthreshold,
						"dbmonitordatabase":dbmonitordatabase,
						"dbmonitordatabaseuser":dbmonitordatabaseuser,
						"dbmonitordatabasepwd":dbmonitordatabasepwd,
						"dbmonitortable":dbmonitortable,
						"dbmonitorcondition":dbmonitorcondition,
						"dbmonitorthreshold":dbmonitorthreshold,
						"displayname":displayname
					},function(data){
				var result=eval('('+data+')');
				if(result.result==true)
				{
					confirm("添加成功");
					commonAjax("jobAlarmAddPage.html");
				}
				else
				{
					confirm("添加失败，请稍候重试");
					commonAjax("jobAlarmAddPage.html");
				}
			});
		}
	}
});

jQuery(document).on("click",".joboperate",function(){
	// alert(jQuery(this).attr("operate-type")+jQuery(this).attr("job-display-name"));
	jQuery.post("jobOperate.html",{
		"ran":getRandom(),
		"operate":jQuery(this).attr("operate-type"),
		"displayname":jQuery(this).attr("job-display-name"),
		},function(data){
		var result=eval('('+data+')');
		if(result.result==true)
		{
			confirm("操作成功");
		}
		else
		{
			confirm("操作异常，请检查状态");
		}
		commonAjax("jobOperatePage.html");
	});
});


jQuery(document).on("click",".cronoperate",function(){
	var input = jQuery('<input id="newcron_input" data-jobname="'+jQuery(this).attr("job-display-name")+'" type="text" value="'+jQuery(this).attr("cron")+'"/>');
	jQuery("#modalbody").html('');
	jQuery("#modalbody").append(input);
	jQuery("#mymodal").modal({
		backdrop:true,
		keyboard:true
		});
});

jQuery(document).on("click","#cronsave_btn",function(){
	var newcron=jQuery("#newcron_input").val();
	var jobname=jQuery("#newcron_input").attr("data-jobname");
// alert(newcron);
// alert(jobname);
	jQuery.post("jobOperate.html",{
		"ran":getRandom(),
		"operate":"CHANGECRON",
		"displayname":jobname,
		"cron":newcron
		},function(data){
		var result=eval('('+data+')');
		if(result.result==true)
		{
			confirm("操作成功");
		}
		else
		{
			confirm("操作异常，请检查状态");
		}
		jQuery("#mymodal").modal("hide");
		commonAjax("jobOperatePage.html");
	});
});

jQuery(document).on("click",".jobmodify",function(){
	jQuery("#jobinfomodal").modal({
		backdrop:true,
		keyboard:true
		});
});


jQuery("#modifyPWD").on("hidden.bs.modal", function() {
	jQuery("#oldPWD").val("");
	jQuery("#newPWD").val("");
	jQuery("#newPWDRepeat").val("");
});

jQuery("#btn_modifypwd").click(function(){
	if(jQuery('#newpwdrepeat').val()==jQuery('#newpwd').val())
	{
		jQuery.post("changePwd.html",{
			"ran":getRandom(),
			"pwd":jQuery('#pwd').val(),
			"newpwd":jQuery('#newpwd').val(),
			},function(data){
			if(data=="true")
			{
				confirm("密码修改成功，请重新登录");
				window.location.href="logout.html";
			}
			else
			{
				confirm("操作异常，请检查状态");
			}
		});
	}
	else
	{
		alert('两次输入的新密码不一致，请重新输入');
	}
});